<?php

class Common_Plugin_Acl extends Zend_Controller_Plugin_Abstract {

	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		$acl = Zend_Registry::get('acl');
		$usersNs = new Zend_Session_NameSpace('members');
		$module = $this->getRequest()->getModuleName();
		$controller = $this->getRequest()->getControllerName();
		$action = $this->getRequest()->getActionName();
		If (($userType = $usersNs -> userType) == '') {
			$roleName = 'guest';
		} else {
			$roleName = $userType;
		}
		$privilageName = $request -> getActionName();
		if (!$acl -> isAllowed($roleName, "$module:$controller", $privilageName)) {
			$request->setModuleName('default');	
			$request -> setControllerName('Error');
			$request -> setActionName('index');
		}
	}

}
?>